import java.util.HashMap;

import java.util.Map;
import java.util.Scanner;
import java.util.Set;


public class TestMap3 {
    public static void main(String[] args) {

        Map<Integer,String> hashMap = new HashMap<>();
        hashMap.put(20210322,"A");
        hashMap.put(20210321,"E");
        hashMap.put(20210323,"B");
        hashMap.put(20210324,"D");
        //遍历
        traverse(hashMap);
        //查询
        map(hashMap);
    }
    public static void traverse(Map<Integer,String> hashMap){
        System.out.println("遍历学生信息：");
        Set<Integer> set = hashMap.keySet();
        for (Integer key:set){
            String value = hashMap.get(key);
            System.out.println("id:"+key+" 姓名："+value);
        }
    }
    public static void map(Map<Integer,String> hashMap){
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入要查询的学号");
        int id = scan.nextInt();
        if (hashMap.get(id)==null){
            System.out.println("学号错误，无此类学生");
        }else {
            System.out.println("学生的姓名为："+hashMap.get(id));
        }
    }
}
